package com.le.beans;

import com.le.utils.Constant;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

// 设置各关卡的背景和障碍物
public class BackGround {
    // 需要记录当前场景的背景图片
    private BufferedImage bg;

    // 记录当前关卡
    private int level;

    // 创建一个集合，存放障碍物
    private List<Obstacle> obstacles = new ArrayList<>();

    public BackGround() {
    }

    public BackGround(BufferedImage bg) {
        this.bg = bg;
    }

    public BackGround(int level) {
        this.level = level;
        // 准备背景图片
        bg = Constant.bg;
        // 设置关卡中的障碍物
        if(level == 1){
            // 第一关
            obstacles.add(new Obstacle(100, 370, 0, this));
            obstacles.add(new Obstacle(130, 370, 1, this));
            obstacles.add(new Obstacle(160, 370, 0, this));
            obstacles.add(new Obstacle(190, 370, 1, this));

            obstacles.add(new Obstacle(300, 260, 0, this));
            obstacles.add(new Obstacle(330, 260, 0, this));
            obstacles.add(new Obstacle(360, 260, 0, this));
            obstacles.add(new Obstacle(390, 260, 0, this));

            obstacles.add(new Obstacle(800, 300, 0, this));
            obstacles.add(new Obstacle(830, 300, 1, this));
            obstacles.add(new Obstacle(860, 300, 0, this));

            // 下水道的描述
            // 水管的底部
            obstacles.add(new Obstacle(420, 420, 4, this));// 左侧
            obstacles.add(new Obstacle(450, 420, 5, this));// 右侧
            // 水管的顶部
            obstacles.add(new Obstacle(415, 390, 2, this));// 左侧
            obstacles.add(new Obstacle(435, 390, 2, this));
            obstacles.add(new Obstacle(455, 390, 3, this));// 右侧


            // 水管的底部
            obstacles.add(new Obstacle(600, 420, 4, this));// 左侧
            obstacles.add(new Obstacle(630, 420, 5, this));// 右侧
            obstacles.add(new Obstacle(600, 390, 4, this));// 左侧
            obstacles.add(new Obstacle(630, 390, 5, this));// 右侧
            // 水管的顶部
            obstacles.add(new Obstacle(595, 360, 2, this));// 左侧
            obstacles.add(new Obstacle(615, 360, 2, this));
            obstacles.add(new Obstacle(635, 360, 3, this));// 右侧
        } else if(level == 2){
            // 第二关
            int temp = 1;
            for (int i = 100; i <= 200; i+=30){
                for (int j = 420; j > 420-temp*30; j-=30){
                    obstacles.add(new Obstacle(i, j, 0, this));
                }
                temp++;
            }
            temp = 1;
            for (int i = 100+8*30; i >= 100+5*30; i-=30){
                for (int j = 420; j > 420-temp*30; j-=30){
                    obstacles.add(new Obstacle(i, j, 0, this));
                }
                temp++;
            }


            temp = 1;
            for (int i = 600; i <= 600+30*4; i+=30){
                for (int j = 420; j > 420-temp*30; j-=30){
                    obstacles.add(new Obstacle(i, j, 0, this));
                }
                temp++;
            }
            temp = 1;
            for (int i = 600+8*30; i >= 600+4*30; i-=30){
                for (int j = 420; j > 420-temp*30; j-=30){
                    obstacles.add(new Obstacle(i, j, 0, this));
                }
                temp++;
            }
        }
    }

    public BufferedImage getBg() {
        return bg;
    }

    public void setBg(BufferedImage bg) {
        this.bg = bg;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public List<Obstacle> getObstacles() {
        return obstacles;
    }

    public void setObstacles(List<Obstacle> obstacles) {
        this.obstacles = obstacles;
    }
}
